package cn.panshi.cdcdemo;

import java.util.HashMap;
import java.util.Map;

import javax.annotation.Resource;

import org.bson.Document;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import cn.panshi.cdcdemo.MongoCdcTtlTaskRouter.TTL_TASK_TYPE;
import cn.panshi.mongocdc.CdcTtlTaskDoc;
import cn.panshi.mongocdc.MongoCdcTtlTaskUtil;
import lombok.extern.slf4j.Slf4j;

@RestController
@Slf4j
public class HelloController {
	private @Resource MongoCdcTtlTaskUtil mongoCdcTtlTaskUtil;
	private @Resource MongoTemplate mongoTemplateSecondary;
	private @Resource MongoTemplate mongoTemplate;

	@SuppressWarnings("rawtypes")
	@GetMapping("/hello/say")
	@ResponseBody
	public Map say() {
		log.debug(mongoCdcTtlTaskUtil + "");
		Document taskBizData = new Document().append("k", "v");
		CdcTtlTaskDoc task = mongoCdcTtlTaskUtil.newTask("hello", TTL_TASK_TYPE.Test, taskBizData, 10);

		Map<Object, Object> map = new HashMap<Object, Object>();
		map.put("msg1", "Spring");
		map.put("msg2", "Boot");

		CdcTtlTaskDoc findById = mongoTemplateSecondary.findById(task.getId(), CdcTtlTaskDoc.class,
				CdcTtlTaskDoc.TABLE);
		log.debug("mongoTemplateSecondary.findById:" + findById);

		findById = mongoTemplate.findById(task.getId(), CdcTtlTaskDoc.class, CdcTtlTaskDoc.TABLE);
		log.debug("mongoTemplate.findById:" + findById);
		return map;
	}

}